package com.zhiche.lisa.bms.controller.bill;

import com.zhiche.lisa.bms.dao.model.bill.ExceptionBillDtl;
import com.zhiche.lisa.bms.pojo.vo.bill.BillExceptionVO;
import com.zhiche.lisa.bms.service.bill.ExceptionBillDtlService;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: liuanshun
 * @Description:
 * @Date: Create in 16:41 2018/10/18
 */
@RestController
@RequestMapping("/billException")
@Api(value = "/billException", description = "账单异常接口", tags = {"账单异常接口"})
public class BillException {
    private static final Logger LOGGER = LoggerFactory.getLogger(BillIoDetailController.class);

    @Autowired
    private ExceptionBillDtlService exceptionBillDtlService;

    @PostMapping(value = "/queryExceptionDetailByBillId/{id}")
    @ApiOperation(value = "查询账单异常信息根据billId", notes = "查询账单异常信息根据billId", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = ExceptionBillDtl.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<BillExceptionVO>> queryBillIoDetailPage(@PathVariable("id") String billId) {
        RestfulResponse<List<BillExceptionVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(exceptionBillDtlService.selectExceptionBillDtlByBillId(billId));
        } catch (BaseException e) {
            LOGGER.error("/BillIoDetailController.queryBillIoDetailPage ERROR: " + e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/BillIoDetailController.queryBillIoDetailPage ERROR: " + e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }
}
